package com.slofzx.nuoda.evaluation.project.controller;

import com.slofzx.nuoda.common.annotation.SysLog;
import com.slofzx.nuoda.evaluation.project.dto.ProjectInfoDTO;
import com.slofzx.nuoda.evaluation.project.dto.ProjectInfoSaveDTO;
import com.slofzx.nuoda.evaluation.project.enums.BatchQualityEnum;
import com.slofzx.nuoda.evaluation.project.vo.ProjectInfoVO;
import com.slofzx.nuoda.evaluation.project.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.slofzx.nuoda.common.controller.BaseController;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.common.vo.PageResultVO;
import com.slofzx.nuoda.common.enums.ServiceResult;

import java.util.*;

/**
 * 项目信息控制层
 *
 * @author nuoda
 * @menu 项目信息
 * @since 2023-10-20 11:04:05
 */
@RestController
@RequestMapping("/project_info")
public class ProjectInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ProjectInfoService projectInfoService;

    @PostMapping("/data")
    public AjaxResultVO<List<ProjectInfoVO>> queryList(@RequestBody ProjectInfoDTO dto) {
        if (BatchQualityEnum.PLAN.getId().equals(dto.getQuality())) {
            final boolean batchName = dto.isBatchName();
            final String batchId = dto.getBatchId();
            String quality = dto.getQuality();
            dto = new ProjectInfoDTO();
            dto.setBatchId(batchId);
            dto.setBatchName(batchName);
            dto.setQuality(quality);
        }
        List<ProjectInfoVO> dataList = projectInfoService.queryVOList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }
    @GetMapping("/nameList")
    public AjaxResultVO<List<ProjectInfoVO>> queryNameList(ProjectInfoDTO dto) {
        List<ProjectInfoVO> dataList = projectInfoService.queryList(dto);
        return AjaxResultVO.newSuccessResult(dataList);
    }

    @ResponseBody
    @PostMapping(value = "/create")
    public AjaxResultVO create(@RequestBody ProjectInfoSaveDTO dto) {
        ServiceResult resultEnum = projectInfoService.create(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @ResponseBody
    @PostMapping(value = "/update")
    public AjaxResultVO update(@RequestBody ProjectInfoSaveDTO dto) {
        ServiceResult resultEnum = projectInfoService.update(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @SysLog(title = "删除评价任务中关联的项目",group = "评价任务")
    @ResponseBody
    @PostMapping(value = "/delete")
    public AjaxResultVO delete(@RequestParam String id) {
        ServiceResult resultEnum = projectInfoService.deleteById(id);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @ResponseBody
    @GetMapping(value = "/info/{id}")
    public AjaxResultVO<ProjectInfoVO> queryById(@PathVariable String id) {
        ProjectInfoVO vo = projectInfoService.queryById(id);
        return AjaxResultVO.newSuccessResult(vo);
    }

    @ResponseBody
    @PostMapping(value = "/edit_project")
    public AjaxResultVO editProjectYearData(@RequestBody ProjectInfoSaveDTO dto) {
        ServiceResult resultEnum = projectInfoService.editProjectYearData(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

}
